import 'package:BeeApp/MainPage/MainPurseListPage.dart';
import 'package:BeeApp/MainPage/MainTiXianPage.dart';

import 'package:BeeApp/MainPage/MainToolPage.dart';
import 'package:flutter/material.dart';

class CarPursePage extends StatefulWidget {
  CarPursePage({Key key}) : super(key: key);

  @override
  _MainUserPageState createState() => _MainUserPageState();
}

class _MainUserPageState extends State<CarPursePage> {
  double topH = 100;
  String money;
  TabController _controller;
  List tabs = ["提现明细", "收入明细"];
  List pages;

  @override
  void initState() {
    super.initState();
    pages = [
      CarPurseListPage(
        2,
        chooseV: (model) {
          if (mounted) {
            setState(() {
              money = model;
            });
          }
        },
      ),
      CarPurseListPage(
        1,
        chooseV: (model) {
          print(model);
          if (mounted) {
            setState(() {
              money = model;
            });
          }
        },
      )
    ];
    _controller = TabController(
      length: tabs.length,
      vsync: ScrollableState(),
    );

    setState(() {
      money = getData("money");
    });
  }

  @override
  void dispose() {
    super.dispose();
    _controller?.removeListener(() {});
    _controller?.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Color(0xFFFFFFFF),
      appBar: getAppBar(context, "钱包"),
      body: Container(
        child: Column(
          children: <Widget>[
            topView(),
            TabBar(
              labelColor: Color(0xFF222222),
              labelStyle: TextStyle(
                fontSize: setFontSize(32),
                fontWeight: FontWeight.bold,
              ),
              unselectedLabelColor: Color(0xFF999999),
              indicatorColor: Color(0xFFFF8629),
              controller: _controller,
              indicatorSize: TabBarIndicatorSize.label,
              //生成Tab菜单
              tabs: tabs.map((e) => Tab(text: e)).toList(),
            ),
            Expanded(
              child: TabBarView(
                  controller: _controller,
                  children: pages.map((e) => Tab(child: e)).toList()),
            )
          ],
        ),
      ),
    );
  }

  Widget topView() {
    return Container(
      height: setHeight(250),
      decoration: BoxDecoration(
        image: DecorationImage(
          image: AssetImage("images/QianBaoTopImage.png"),
          fit: BoxFit.cover,
        ),
      ),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: <Widget>[
          Container(
            padding: EdgeInsets.fromLTRB(
              setWidth(70),
              setHeight(60),
              setWidth(30),
              0,
            ),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                Text(
                  "金额",
                  style: TextStyle(
                    color: Color(0xFF654B00),
                    fontSize: setFontSize(28),
                  ),
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: <Widget>[
                    Text(
                      money == null ? "0.00" : money,
                      style: TextStyle(
                        color: Color(0xFF654B00),
                        fontSize: setFontSize(67),
                      ),
                    ),
                    InkWell(
                      child: Container(
                        padding: EdgeInsets.fromLTRB(
                          setWidth(50),
                          setHeight(15),
                          setWidth(50),
                          setHeight(15),
                        ),
                        decoration: BoxDecoration(
                          borderRadius: BorderRadius.all(Radius.circular(20.0)),
                          border:
                              Border.all(color: Color(0xFF654B00), width: 1),
                        ),
                        child: Text(
                          "提现",
                          style: TextStyle(
                            color: Color(0xFF654B00),
                            fontSize: setFontSize(24),
                          ),
                        ),
                      ),
                      onTap: () {
                        print("object");
                        Navigator.push(
                            context,
                            MaterialPageRoute(
                                builder: (context) => MainTiXianPage()));
                      },
                    ),
                  ],
                ),
              ],
            ),
          ),
          Container(
            height: 8,
            decoration: BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.only(
                topLeft: Radius.circular(10.0),
                topRight: Radius.circular(10.0),
              ),
            ),
          )
        ],
      ),
    );
  }
}
